<?php
/**
 * Page Template
 *
 * Loaded automatically by index.php?main_page=product_info.<br />
 * Displays details of a typical product
 */
//get product listing follow product master
global $db;
$selector_string = "";
$sql_listing = "select p.products_id, pd.products_name, pd.products_short_name,
                  p.products_quantity, p.products_image,
                  p.products_price,
                  p.products_tax_class_id,
                  p.products_date_available, p.manufacturers_id,
                  p.products_weight, p.products_priced_by_attribute, p.product_is_free,
                  p.products_qty_box_status,
                  p.products_quantity_order_max,
                  p.products_discount_type, p.products_discount_type_from, p.products_sort_order, p.products_price_sorter, p.products_expiration_date,
                  p.products_dosis, pd.products_tagline, pd.products_label, pd.products_usage, pd.products_presentation, p.products_master_id
           from   " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd
           where  p.products_status = '1'
           and    (p.products_id = '" . (int)$_GET['products_id'] . "' or p.products_master_id = '" . (int)$_GET['products_id'] . "')
           and    pd.products_id = p.products_id
           and    pd.language_id = '" . (int)$_SESSION['languages_id'] . "'";

$product_listings = $db->Execute($sql_listing);
if ( PRODUCTS_OPTIONS_SORT_BY_PRICE =='1' ) {
    $order_by= ' order by LPAD(pa.products_options_sort_order,11,"0"), pov.products_options_values_name';
} else {
    $order_by= ' order by LPAD(pa.products_options_sort_order,11,"0"), pa.options_values_price';
}
while (!$product_listings->EOF) {
    //write product info
    ?>
<div style="margin-top: 15px">
    <div><?php echo $product_listings->fields['products_short_name'] . zen_get_products_display_price((int)$product_listings->fields['products_id']); ?> </div>
<!--bof Add to Cart Box -->
<?php
    if (CUSTOMERS_APPROVAL == 3 and TEXT_LOGIN_FOR_PRICE_BUTTON_REPLACE_SHOWROOM == '') {
  // do nothing        
    } else {
?>
    <?php
        $products_quantity = $product_listings->fields['products_quantity'];
        $products_qty_box_status = $product_listings->fields['products_qty_box_status'];
        $products_quantity_order_max = $product_listings->fields['products_quantity_order_max'];
        $flag_show_product_info_in_cart_qty = zen_get_show_product_switch($product_listings->fields['products_id'], 'in_cart_qty');
        $title_add_to_cart = META_TAGS_BUY . " " . $product_listings->fields['products_short_name'];
        $display_qty = (($flag_show_product_info_in_cart_qty == 1 and $_SESSION['cart']->in_cart($product_listings->fields['products_id'])) ? '<p>' . PRODUCTS_ORDER_QTY_TEXT_IN_CART . $_SESSION['cart']->get_quantity($product_listings->fields['products_id']) . '</p>' : '');
        if ($products_qty_box_status == 0 or $products_quantity_order_max== 1) {
            // hide the quantity box and default to 1
            $the_button = '<input type="hidden" name="cart_quantity" value="1" />' . zen_draw_hidden_field('products_id', (int)$product_listings->fields['products_id']) . zen_image_submit(BUTTON_IMAGE_IN_CART, $title_add_to_cart);//, BUTTON_IN_CART_ALT);
        } else {
              // show the quantity box
            $the_button = '<input type="text" name="cart_quantity" value="' . (zen_get_buy_now_qty($product_listings->fields['products_id'])) . '" maxlength="6" size="3" />' . zen_get_products_quantity_min_units_display((int)$product_listings->fields['products_id']) . zen_draw_hidden_field('products_id', (int)$product_listings->fields['products_id']) . zen_image_submit(BUTTON_IMAGE_IN_CART, $title_add_to_cart);//, BUTTON_IN_CART_ALT);
        }
        $display_button = zen_get_buy_now_button($product_listings->fields['products_id'], $the_button);
        
        //get the attribute option listings
        $sql = "select    pov.products_options_values_id,
                        pov.products_options_values_name, pa.options_id
              from      " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov LEFT JOIN " . TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . " pwas ON pwas.stock_attributes = pa.products_attributes_id
              WHERE   pa.products_id = '" . (int)$product_listings->fields['products_id'] . "'
                   and    pa.options_id = '" . (int)$products_options_names->fields['products_options_id'] . "'
                and    (pwas.quantity > 0 or pwas.quantity IS NULL)
                  and    pa.options_values_id = pov.products_options_values_id
                 and       pov.language_id = '" . (int)$_SESSION['languages_id'] . "' " .
        $order_by;

        $products_options = $db->Execute($sql);
  ?>
  <?php if ($display_qty != '' or $display_button != '') {       
      if (is_null($product_back_in_stock_notification_form_link)){?>
    
    <?php      
      // BEGIN CEON BACK IN STOCK NOTIFICATIONS 1 of 2
        if (!is_null($product_back_in_stock_notification_form_link)) {
            echo '<p>' . $product_back_in_stock_notification_form_link . '</p>';
        }
// END CEON BACK IN STOCK NOTIFICATIONS 1 of 2
      ?>
    <!--bof Attributes Module -->
    <?php
    // show product listing follow attribute
    
            if ($products_options->RecordCount() > 0) {
                while(!$products_options->EOF)
                {            
                    echo zen_draw_form('cart_quantity', zen_href_link(zen_get_info_page($_GET['products_id']), zen_get_all_get_params(array('action')) . 'action=add_product', $request_type), 'post', 'enctype="multipart/form-data"') . "\n";
            ?>   
        <div id="">
            <div style="float: left; width: 170px"><?php echo $products_options->fields['products_options_values_name']; ?>
                <input type="hidden" name="id[<?php echo $products_options->fields['options_id']; ?>]" value="<?php echo $products_options->fields['products_options_values_id']; ?>" />
            </div>
            <div style="float: right; width: 68px"><?php echo $display_qty; echo $display_button;  ?></div>
            <div class="clearBoth"></div>
        </div>
    </form>
    <?php
                    $products_options->MoveNext();
                }
            }
            else
            {
                echo zen_draw_form('cart_quantity', zen_href_link(zen_get_info_page($_GET['products_id']), zen_get_all_get_params(array('action')) . 'action=add_product', $request_type), 'post', 'enctype="multipart/form-data"') . "\n";
?>
     <div id="">
            <div style="float: left; width: 170px">
            </div>
            <div style="float: right; width: 68px"><?php echo $display_qty; echo $display_button;  ?></div>
            <div class="clearBoth"></div>
        </div>
    </form>   
<?php
            }
    ?>
    <!--eof Attributes Module -->            
<?php
    }
    else if($products_quantity > -1) {
    // BEGIN CEON BACK IN STOCK NOTIFICATIONS 1 of 2  
    ?>
    <div id="">
        <div style="text-align: right; padding-right: 60px">
            <?php echo $display_button;?>
        </div>
        <div style="padding-left: 5px; font-weight: bold">
            <?php echo BACK_IN_STOCK_NOTIFICATION_TEXT_FORM_TITLE;?>
        </div>
        <div style="text-align:right">
            <p><?php 
                $intro_text = sprintf(BACK_IN_STOCK_NOTIFICATION_TEXT_FORM_INTRO, htmlentities($products_name, ENT_COMPAT, CHARSET));
                echo $intro_text; 
            ?></p>            
            <label for="name"><?php echo BACK_IN_STOCK_NOTIFICATION_TEXT_FORM_ENTRY_NAME;?></label>
            <input type="text" size="25" maxlength="64" id="name" value="<?php echo $back_in_stock_notification_form_customer_name; ?>">
            <br class="clearBoth">
            <label for="email"><?php echo BACK_IN_STOCK_NOTIFICATION_TEXT_FORM_ENTRY_EMAIL;?></label>
            <input type="text" size="25" maxlength="96" id="email" value="<?php echo $back_in_stock_notification_form_customer_email; ?>">
            <br class="clearBoth">            
        </div>
        <div class="buttonRow forward">
            <a onclick="submit()" href="javascript:void(0)">
                <?php echo '<img width="69" height="21" title=" ' . BUTTON_NOTIFY_ME_ALT . ' " alt="' . BUTTON_NOTIFY_ME_ALT 
                        . '" src="includes/templates/template_default/buttons/' . $_SESSION['language'] . '/notify_me.png" />'; ?></a>
        </div>
    </div>
<?php
    }
// END CEON BACK IN STOCK NOTIFICATIONS 1 of 2
            ?>		

  <?php } // display qty and button ?>
<?php } // CUSTOMERS_APPROVAL == 3 ?>
<!--eof Add to Cart Box-->
</div>
<?php
    if(isset($product_listings->fields['products_master_id']))
        $selector_string .= "<option value='" . $product_listings->fields['products_dosis'] . "' selected='selected'>" . $product_listings->fields['products_name'] . "</option>";
    else
        $selector_string .= "<option value='" . $product_listings->fields['products_dosis'] . "'>" . $product_listings->fields['products_name'] . "</option>";
    $product_listings->MoveNext();
}
if(!empty($selector_string))
{
?>
<select id="size_selector" onchange="selector()">
    <?php echo $selector_string; ?>
</select>
<?
}
?>